$(document).ready(function() {
	var epamEvoData = [];
	var citiesInfo = {};

	function initSlider(maxQuarter) {
		$("#slider").slider({
			min : 1,
			max : maxQuarter,
			change : function(event, ui) {
				map.update(ui.value);
			}
		});
	}

	function init() {
	    $.when(getReprChartAjaxCall(), getEmplGrowingChartData(), getOffGrowingChartData(), getNumberOfQuarters()).done(function(reprData, emplData, offData, numberOfQuarters) {

            charts.setOptions({
                reprData : reprData[0],
                emplData : emplData[0],
                offData : offData[0]
            });

            charts.render();

            map.render();
            map.update(1);

            initSlider(numberOfQuarters[0].numOfQuarters);
	    });
	}


    function getReprChartAjaxCall() {
        return $.getJSON("/restService/represent-data");
    }

    function getEmplGrowingChartData() {
        return $.getJSON("/restService/emp-grow-data");
    }

    function getOffGrowingChartData() {
        return $.getJSON("/restService/off-grow-data");
    }
    function getNumberOfQuarters() {
        return $.getJSON("/restService/quarters-number");
    }

	init();
});